import java.util.Arrays;

public class SolutionLCP50 {
    public int giveGem(int[] gem, int[][] operations) {
        for (int[] operation : operations) {
            int t=gem[operation[0]]/2;
            gem[operation[0]]-=t;
            gem[operation[1]]+=t;
        }
        int a= Arrays.stream(gem).min().getAsInt();
        int b=Arrays.stream(gem).max().getAsInt();
        return b-a;
    }

    public static void main(String[] args) {
        System.out.println(new SolutionLCP50().giveGem(new int[]{3,1,2},new int[][]{{0,2},{2,1},{2,0}}));
    }
}
